home *** CD-ROM | disk | FTP | other *** search
- #
- # The Python Imaging Library
- # $Id: ImageDraw.py,v 1.1.1.2 1999/01/13 09:40:25 sjoerd Exp $
- #
- # drawing interface operations
- #
- # History:
- # 96-04-13 fl Created (experimental)
- # 96-08-07 fl Filled polygons, ellipses.
- # 96-08-13 fl Added text support
- # 98-06-28 fl Handle I and F images
- # 98-12-29 fl Added arc; use arc primitive to draw ellipses
- #
- # Copyright (c) Secret Labs AB 1997-98.
- # Copyright (c) Fredrik Lundh 1996.
- #
- # See the README file for information on usage and redistribution.
- #
-
- import Image
- import math
-
- class ImageDraw:
-
- def __init__(self, im):
- im.load(1)
- self.im = im.im
- self.image = im
- if im.mode in ("I", "F"):
- self.ink = self.im.draw_ink(1)
- else:
- self.ink = self.im.draw_ink(-1)
- self.fill = 0
- self.font = None
-
- def setink(self, ink):
- self.ink = self.im.draw_ink(ink)
-
- def setfill(self, onoff):
- self.fill = onoff
-
- def setfont(self, font):
- self.font = font
-
- def arc(self, xy, start, end):
- self.im.draw_arc(xy, start, end, self.ink)
-
- def chord(self, xy, start, end):
- self.im.draw_chord(xy, start, end, self.ink, self.fill)
-
- def line(self, xy, xy1 = None):
- if xy1:
- self.im.draw_line(xy, xy1, self.ink)
- else:
- self.im.draw_lines(xy, self.ink)
-
- def pieslice(self, xy, start, end):
- self.im.draw_pieslice(xy, start, end, self.ink, self.fill)
-
- def point(self, xy):
- self.im.draw_points(xy, self.ink)
-
- def polygon(self, xy):
- self.im.draw_polygon(xy, self.ink, self.fill)
-
- def rectangle(self, xy):
- self.im.draw_rectangle(xy, self.ink, self.fill)
-
- def ellipse(self, xy):
- self.im.draw_ellipse(xy, self.ink, self.fill)
-
- def text(self, xy, text):
- import ImageFont
- if not self.font:
- # FIXME: add font repository
- self.font = ImageFont.load_path("BDF/courR14.pil")
- x, y = xy
- m = self.font.getmask(text)
- self.image.paste(self.ink, (x, y, x + m.size[0], y + m.size[1]), m)
-